home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14265 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  51 lines

  1. Path: dispatch.news.demon.net!demon!asta.demon.co.uk
  2. From: Mark Billingham <mark@astadev.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Templates & Friend classes
  5. Date: Fri, 29 Mar 1996 18:03:09 +0000
  6. Organization: Asta Development Corporation
  7. Message-ID: <315C25DD.4481@astadev.com>
  8. NNTP-Posting-Host: asta.demon.co.uk
  9. X-NNTP-Posting-Host: asta.demon.co.uk
  10. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  11. MIME-Version: 1.0
  12. Content-Type: text/plain; charset=us-ascii
  13. Content-Transfer-Encoding: 7bit
  14.  
  15. How can you make a templated class a friend of a non templated class ?
  16.  
  17. I have a set of templated array classes which derive from a common base
  18. class (which is non templated).
  19.  
  20. Alongside these classes I have have some templated iterators, the non
  21. templated array base class has member functions which are used only
  22. by the iterators. I would like to make these function private and allow
  23. the iterators to access them by making them friends of the array base 
  24. class. But alas, I can't figure out how to do it.
  25.  
  26.  
  27. to illustate,
  28.  
  29. class ARRAY_BASE
  30. {
  31.     friend ??????; // how to make templated class a friend
  32.  
  33.     private:
  34.         UsedByIterators();
  35. };
  36.  
  37. template <class T> class ARRAY<T> : public ARRAY_BASE
  38. {
  39.     ...
  40. };
  41.  
  42. template <class T> class ARRAY_ITERATOR
  43. {
  44.     private:
  45.         ARRAY<T> m_array&;
  46.     bool Next();
  47.     {
  48.         m_array.UsedByIterator();   // Can't its private
  49.     }    
  50. };
  51.